package com.xiaohong.mq.sender;

import com.alibaba.fastjson.JSON;
import com.xiaohong.mq.pojo.SendMsg;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : xiaohong
 * @date : 2021/4/13 16:49
 * 消息发送者
 */

@RestController
@CrossOrigin
@RequestMapping("/sent")
public class MQSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/chat")
    public String send(@RequestParam String msg){
        // 交换机名称  路由key/queue队列名称  消息内容
        // 路由模式更具不同的路由key来发送给不同的队列
        rabbitTemplate.convertAndSend("chat_exchange","chat", msg);
        return "发送消息成功:  "+msg;
    }
}
